#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 1000010;
char s[N];
int ne[N];
int n;
int main()
{
    int T = 1;
    while (scanf("%d", &n), n)
    {
        scanf("%s", s + 1);
        for (int i = 2; i <= n; i++)
        {
            int j = ne[i - 1];
            while (j && s[i] != s[j + 1]) j = ne[j];
            if (s[i] == s[j + 1]) j++;
            ne[i] = j;
        }
        printf("Test case #%d\n", T++);
        for (int i = 1; i <= n; i++)
        {
            int m = i - ne[i];
            if (i % m == 0 && i / m > 1)
            {
                printf("%d %d\n", i, i / m);
            }
        }
        puts("");
    }
    return 0;
}